﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 单位转换器2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;
            comboBox4.SelectedIndex = 0;
            comboBox5.SelectedIndex = 0;
            comboBox6.SelectedIndex = 0;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
            comboBox7.SelectedIndex = 0;
            comboBox8.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            string str1, str2;
            str1 = Convert.ToString(comboBox7.SelectedItem);
            str2 = Convert.ToString(comboBox8.SelectedItem);
            double d1, d2;
            if (textBox7.Text == "")
            {
                textBox7.Text = "1";
                d1 = 1;
            }
            else
                d1 = Convert.ToDouble(textBox7.Text);
            if(str1==str2)
            {
                d2 = d1;
                textBox8.Text = Convert.ToString(d2);
            }
                else{

                    if(str1=="摄氏度"&&str2== "华氏度"){
                        d2=1.8*d1+32;
                        textBox8.Text=Convert.ToString(d2);
                    }
                    if(str1=="摄氏度"&&str2== "开氏度"){
                        d2=d1+273.15;
                        textBox8.Text=Convert.ToString(d2);
                    }
                    if(str1=="摄氏度"&&str2== "摄氏度"){
                        d2=(d1-32)/1.8;
                        textBox8.Text=Convert.ToString(d2);
                    }
                    if(str1=="摄氏度"&&str2== "开氏度"){
                        d2=(d1-32)/1.8+273.15;
                        textBox8.Text=Convert.ToString(d2);
                    }
                    if(str1=="摄氏度"&&str2== "摄氏度"){
                        d2=d1-273.15;
                        textBox8.Text=Convert.ToString(d2);
                    }
                    if(str1=="摄氏度"&&str2== "华氏度"){
                        d2=(d1-273.15)*1.8+32;
                        textBox8.Text=Convert.ToString(d2);
                    }
                }
            }
        

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar !='\b' && e.KeyChar !=46)
            {

                if((e.KeyChar<'0')||(e.KeyChar>'9'))
                {
                    e.Handled=true;
                }
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\b' && e.KeyChar != 46)
            {

                if ((e.KeyChar < '0') || (e.KeyChar > '9'))
                {
                    e.Handled = true;
                }
            }
        }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\b' && e.KeyChar != 46)
            {

                if ((e.KeyChar < '0') || (e.KeyChar > '9'))
                {
                    e.Handled = true;
                }
            }
        }

        

       
    }
}
